package com.my.mytest.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;

/**
 * Created by Android Studio.
 * User: mwb
 * Date: 2020/12/16 0016
 * Time: 上午 11:25
 * Describe:
 */
public class GlideUtil {

    public static class GlideResultBean {
        public  int height;
        public  int widht;

        public GlideResultBean(int height, int widht) {
            this.height = height;
            this.widht = widht;
        }
    }

    public static void getImageSize(Context context, int imgResources, final CallBack callBack) {
        Glide.with(context)
                .asBitmap()
                .load(imgResources)
                .into(new CustomTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                        if (callBack != null) {
                            GlideResultBean bean = new GlideResultBean(resource.getHeight(), resource.getWidth());
                            callBack.onMeasureImage(bean);
                        }
                    }

                    @Override
                    public void onLoadCleared(@Nullable Drawable placeholder) {
                    }
                });
    }

    public interface CallBack {
        void onMeasureImage(GlideResultBean bean);
    }
}
